macro(source_group_by_dir SOURCE_FILES)
    if(MSVC)
        foreach(SOURCE_CUR_FILE ${${SOURCE_FILES}})
            message(STATUS "${SOURCE_CUR_FILE}")
            string(REGEX REPLACE "(.*/)" "" SOURCE_CUR_FILE_NAME ${SOURCE_CUR_FILE})
            message(STATUS "SOURCE_CUR_FILE_NAME: ${SOURCE_CUR_FILE_NAME}")
            string(REGEX REPLACE "/${SOURCE_CUR_FILE_NAME}" "" SOURCE_GROUP_PATH ${SOURCE_CUR_FILE})
            message(STATUS "SOURCE_GROUP_PATH: ${SOURCE_GROUP_PATH}")

            string(REGEX REPLACE "${CMAKE_CURRENT_SOURCE_DIR}/" "" SOURCE_GROUP_NAME ${SOURCE_GROUP_PATH})
            message(STATUS "CMAKE_CURRENT_SOURCE_DIR: ${CMAKE_CURRENT_SOURCE_DIR} SOURCE_GROUP_NAME: ${SOURCE_GROUP_NAME}")

            string(COMPARE EQUAL ${SOURCE_CUR_FILE_NAME} ${SOURCE_GROUP_NAME} NOGROUP)
            if(NOGROUP)
                set(SOURCE_GROUP_NAME "/")
            endif()
            source_group(${SOURCE_GROUP_NAME} FILES ${SOURCE_CUR_FILE})

        endforeach(SOURCE_CUR_FILE)
    endif(MSVC)
endmacro(source_group_by_dir)
